import VuiElement from '@/components/vui/base/element';
import VuiArrowRight from '../../arrow/arrow-right';
import VuiContainer from '../../container';
import VuiText from '../../text';

/**
 * 下拉菜单选项
 */
export default class VuiDropdownItem extends VuiElement {
  constructor(id, title, icon, hasChild = false, disabled = false) {
    super();
    this._className = {
      container: 'vui-dropdown-item-container',
      icon: 'vui-dropdown-item-icon',
      title: 'vui-dropdown-item-title'
    };
    this._config = { id, title, icon, hasChild, disabled };
  }

  initUI() {
    const cls = this._className;
    const config = this._config;
    this.initContainer(null, config.title, config.id);
    this.setAttribute('value', config.id);
    this.setAttribute('text', config.title);

    const childs = [];
    if (config.icon) {
      childs.push(VuiContainer.newInstance(cls.icon, config.icon));
    }
    childs.push(VuiText.newInstance(config.title, cls.title));

    if (config.hasChild) {
      childs.push(VuiArrowRight.newInstance());
    }
    this.append(childs);
  }
}
